package cn.com.infcn.monitor.web;

import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.http.HttpServletResponse;

class CounterResponseStream extends FilterServletOutputStream {
	private int dataLength;

	CounterResponseStream(HttpServletResponse response) throws IOException {
		super(response.getOutputStream());
	}

	CounterResponseStream(OutputStream output) {
		super(output);
	}

	public int getDataLength() {
		return dataLength;
	}

	public void reset() {
		dataLength = 0;
	}

	@Override
	public void write(int i) throws IOException {
		super.write(i);
		dataLength += 1;
	}

	@Override
	public void write(byte[] bytes) throws IOException {
		super.write(bytes);
		final int len = bytes.length;
		dataLength += len;
	}

	@Override
	public void write(byte[] bytes, int off, int len) throws IOException {
		super.write(bytes, off, len);
		dataLength += len;
	}
}
